<%--
  Created by IntelliJ IDEA.
  User: 赵坚强
  Date: 2020/4/29
  Time: 11:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=utf-8" language="java" errorPage="../404.jsp" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="shortcut icon" href="../file/favicon.ico"/>
    <link rel="bookmark" href="../file/favicon.ico"/>
    <link href="../css/H-ui.min.css" rel="stylesheet" type="text/css"/>
    <link href="../css/H-ui.login.css" rel="stylesheet" type="text/css"/>
    <link href="../libs/h-ui/lib/icheck/icheck.css" rel="stylesheet" type="text/css"/>
    <link href="../libs/h-ui/lib/Hui-iconfont/1.0.1/iconfont.css" rel="stylesheet" type="text/css"/>

    <script type="text/javascript" src="../libs/h-ui/lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="../js/H-ui.min.js"></script>
    <script type="text/javascript" src="../js/jquery.validate.min.js"></script>
    <script type="text/javascript" src="../js/validate-methods.js"></script>
    <script type="text/javascript" src="../js/messages_zh.min.js"></script>
    <script type="text/javascript" src="../js/sha1.js"></script>
<%--    <script type="text/javascript" src="../easyui/js/validateExtends.js"></script>--%>
    <script type="text/javascript" src="../libs/h-ui/lib/icheck/jquery.icheck.min.js"></script>

    <script type="text/javascript">
        $(function () {
            $("#form").validate();
            let sendData = function () {
                let pwd = $("#password").val();
                $("#password").val(sha1(pwd));
                let data = $("#form").serialize();
                $.ajax({
                    type: "post",
                    url: "../loginServlet?method=Login",
                    data: data,
                    dataType: "text", //返回数据类型
                    success: function (msg) {
                        if ("vcodeError" === msg) {
                            alert("验证码错误");
                            $("#vcodeImg").click();//切换验证码
                            $("input[name='password']").val(pwd);
                            $("input[name='vcode']").val("");//清空验证码输入框
                        } else if ("loginError" === msg) {
                            alert("用户名或密码错误!");
                            $("#vcodeImg").click();//切换验证码
                            $("input[name='vcode']").val("");//清空验证码输入框
                            $("input[name='username']").val("");//清空用户名输入框
                            $("input[name='password']").val("");//清空密码输入框
                        } else if ("loginSuccess" === msg) {
                            window.location.href = "../systemServlet?method=toAdminView";
                        } else {
                            console.log(msg);
                        }
                    }

                });
            }
            // 登录按钮绑定单击事件
            $("#submitBtn").click(function () {

                let username = $("#username").val();
                let pwd = $('#password').val();
                let code = $('#code').val();
                // let regexp = /[^ ]+/;

                if (username != "" && pwd.length >= 4 && pwd.indexOf(' ') == -1 && code.length == 4) {
                    sendData();
                } else {
                    // $.messager.alert("消息提醒", "输入格式有误!", "warning");
                    alert("输入格式有误");
                }


            });

            //设置复选框
            $(".skin-minimal input").iCheck({
                radioClass: 'iradio-blue',
                increaseArea: '25%'
            });

            // 点击图片切换验证码
            $("#vcodeImg").click(function () {
                this.src = "../cpachaServlet?method=loginCapcha&t=" + new Date().getTime();
            });

        })
    </script>
    <title>登录|学生管理系统</title>
    <meta name="keywords" content="学生管理系统">
</head>
<body>

<div class="header" style="padding: 0;">
    <h2 style="color: white; width: 400px; height: 60px; line-height: 60px; margin: 0 0 0 30px; padding: 0">学生管理系统</h2>
</div>

<div class="loginWraper">
    <div id="loginform" class="loginBox">

        <form id="form" class="form form-horizontal" method="post">
            <div class="row cl">
                <label class="form-label col-3"><i class="Hui-iconfont">&#xe60d;</i></label>
                <div class="formControls col-8">
                    <input id="username" name="username" type="text" autocomplete="off" placeholder="用户名"
                           class="input-text radius  size-L" minlength="2" required>
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-3"><i class="Hui-iconfont">&#xe60e;</i></label>
                <div class="formControls col-8">
                    <input id="password" name="password" type="password" minlength="6" placeholder="密码，不包含空格"
                           class="input-text  radius size-L" required>
                </div>
            </div>
            <div class="row cl">
                <div class="formControls col-8 col-offset-3">
                    <input class="input-text radius size-L" autocomplete="off" name="vcode" type="text"
                           id="code" placeholder="请输入验证码"
                           style="width: 200px;" required>
                    <img title="点击图片切换验证码" class="radius" id="vcodeImg" src="../cpachaServlet?method=loginCapcha"></div>
            </div>

            <div class="mt-20 skin-minimal" style="text-align: center;">
                <div class="radio-box">
                    <input type="radio" id="radio-2" name="type" checked value="2"/>
                    <label for="radio-2">学生</label>
                </div>
                <div class="radio-box">
                    <input type="radio" id="radio-3" name="type" value="3"/>
                    <label for="radio-3">教师</label>
                </div>
                <div class="radio-box">
                    <input type="radio" id="radio-1" name="type" value="1"/>
                    <label for="radio-1">辅导员</label>
                </div>
            </div>

            <div class="row">
                <div class="formControls col-8 col-offset-3">
                    <input id="submitBtn" type="button" class="btn btn-success radius size-L"
                           value="&nbsp;登&nbsp;&nbsp;&nbsp;&nbsp;录&nbsp;">
                </div>
            </div>

        </form>

    </div>
</div>

<footer class="footer mt-20">
    <div class="container-fluid">
        <nav>
            <p class="footer">Copyright &copy;2020 毕业设计作品 All Rights Reserved. | 赵扬1607020401
            </p>
        </nav>
    </div>
</footer>

</body>
</html>
